package com.evil.kingdom.pojo.dto.person.base;

import com.evil.kingdom.pojo.dto.core.ArmDto;
import com.evil.kingdom.pojo.dto.core.ItemDto;
import com.evil.kingdom.pojo.dto.core.MountDto;
import com.evil.kingdom.pojo.entity.base.Fight;
import com.evil.kingdom.pojo.entity.base.Level;
import com.evil.kingdom.pojo.enums.PersonTypeEnum;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

/**
 * 人物
 *
 * @author liyang
 * @date 2024-05-17 16:00
 */
@Getter
@Setter
public class PersonDto extends Fight implements Level {

    /**
     * 名称
     */
    @NotBlank(message = "名称不能为空")
    private String name;

    /**
     * 年龄
     */
    @NotNull(message = "年龄不能为空")
    private Integer age;

    /**
     * 等级
     */
    private Integer level;

    /**
     * 经验值
     */
    private Integer experience;

    /**
     * 武器
     */
    @Valid
    private ArmDto armDto;

    /**
     * 物品
     */
    @Valid
    private ItemDto itemDto;

    /**
     * 坐骑
     */
    @Valid
    private MountDto mountDto;

    /**
     * 人物类型
     */
    private PersonTypeEnum typeEnum;

    public PersonDto() {
        this.level = 1;
        this.experience = 1;
        this.typeEnum = PersonTypeEnum.KING;
    }

    public PersonDto(String name) {
        this.name = name;
        this.level = 1;
        this.experience = 1;
        this.typeEnum = PersonTypeEnum.KING;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PersonDto personDto = (PersonDto) o;

        return Objects.equals(name, personDto.name);
    }

    @Override
    public int hashCode() {
        return name != null ? name.hashCode() : 0;
    }

    public String printInfo() {
        return String.format("%s:%s", this.name, this.getHp());
    }
}
